package com.neu.servlet.snn;

import com.alibaba.fastjson.JSONObject;
import com.neu.service.snn.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "FindAddressServlet", urlPatterns = {"/FindAddressServlet.do"})
public class FindAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        String u_id = request.getParameter("u_id");
        UserService userService = new UserService();
        List<Map<String,Object>> diZhiList = userService.findAddressById(u_id);
        HttpSession session = request.getSession();
        System.out.println(diZhiList);
        if (diZhiList!=null){
            session.setAttribute("diZhiList",diZhiList);
            String json=JSONObject.toJSONString(diZhiList);
            PrintWriter out=response.getWriter();
            out.print(json);
            out.close();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
